/*
 * @Author: '浪川' '1214391613@qq.com'
 * @Date: 2025-07-05 16:06:20
 * @LastEditors: '浪川' '1214391613@qq.com'
 * @LastEditTime: 2025-08-05 15:35:15
 * @FilePath: \passiflora-edulis-sims\src\stores\CreateBook\general-puzzle-store.ts
 * @Description: 双重拼图 的 状态管理
 *
 * Copyright (c) 2025 by '1214391613@qq.com', All Rights Reserved.
 */
import { defineStore, acceptHMRUpdate } from 'pinia'
import type { Ipage } from 'src/interfaces/IBook'

export const useGeneralPuzzleStore = defineStore('GeneralPuzzlerch', {
  state: (): Ipage => ({
    type: 'double_puzzle',

    title: {
      text: 'A Puzzle Title',
      font: {
        font_name: '',
        font_size: 150,
        font_color: '#000000',
      },
      text_align: 'center',
      vertical_align: 'middle',
      offet_x: 0,
      offet_y: 0,
    },
    instruction: {
      text: 'A Puzzle Title Instruction',
      font: {
        font_name: '',
        font_size: 75,
        font_color: '#1aaeed',
      },
      text_align: 'center',
      vertical_align: 'middle',
      offet_x: 0,
      offet_y: 0,
    },
    page_no: 0,
    game: 'DoublePuzzle',
    word_list: ['Word', 'Card', 'List'],

    answer_frame: undefined,
    topic_frame: undefined,
  }),

  getters: {
    max_wordlen(): number {
      let num = 0
      for (const str of this.word_list) {
        num = str.length > num ? str.length : num
      }
      return num
    },
  },

  actions: {
    set_title(text: string) {
      this.title.text = text
    },
    set_instruction(text: string) {
      this.instruction.text = text
    },
  },
})

if (import.meta.hot) {
  import.meta.hot.accept(
    acceptHMRUpdate(useGeneralPuzzleStore, import.meta.hot)
  )
}
